package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SoilChemistry;
import com.ruoyi.system.service.ISoilChemistryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营养元素Controller
 * 
 * @author ruoyi
 * @date 2024-03-20
 */
@Controller
@RequestMapping("/system/chemistry")
public class SoilChemistryController extends BaseController
{
    private String prefix = "system/chemistry";

    @Autowired
    private ISoilChemistryService soilChemistryService;

    @RequiresPermissions("system:chemistry:view")
    @GetMapping()
    public String chemistry()
    {
        return prefix + "/chemistry";
    }

    /**
     * 查询营养元素列表
     */
    @RequiresPermissions("system:chemistry:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SoilChemistry soilChemistry)
    {
        startPage();
        List<SoilChemistry> list = soilChemistryService.selectSoilChemistryList(soilChemistry);
        return getDataTable(list);
    }

    /**
     * 导出营养元素列表
     */
    @RequiresPermissions("system:chemistry:export")
    @Log(title = "营养元素", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SoilChemistry soilChemistry)
    {
        List<SoilChemistry> list = soilChemistryService.selectSoilChemistryList(soilChemistry);
        ExcelUtil<SoilChemistry> util = new ExcelUtil<SoilChemistry>(SoilChemistry.class);
        return util.exportExcel(list, "营养元素数据");
    }

    /**
     * 新增营养元素
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存营养元素
     */
    @RequiresPermissions("system:chemistry:add")
    @Log(title = "营养元素", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SoilChemistry soilChemistry)
    {
        return toAjax(soilChemistryService.insertSoilChemistry(soilChemistry));
    }

    /**
     * 修改营养元素
     */
    @RequiresPermissions("system:chemistry:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SoilChemistry soilChemistry = soilChemistryService.selectSoilChemistryById(id);
        mmap.put("soilChemistry", soilChemistry);
        return prefix + "/edit";
    }

    /**
     * 修改保存营养元素
     */
    @RequiresPermissions("system:chemistry:edit")
    @Log(title = "营养元素", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SoilChemistry soilChemistry)
    {
        return toAjax(soilChemistryService.updateSoilChemistry(soilChemistry));
    }

    /**
     * 删除营养元素
     */
    @RequiresPermissions("system:chemistry:remove")
    @Log(title = "营养元素", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(soilChemistryService.deleteSoilChemistryByIds(ids));
    }
}
